package com.ibm.cps.sql.expression;

import java.util.HashSet;
import java.util.Set;

import com.ibm.util.exception.CPSException;

public class IdentifierNode implements ValueExpression {
	private String name;
	
	public IdentifierNode() {
		//Only used for serialization
	}

	public IdentifierNode(String name) {
		this.name = name;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return "{\"IdentifierNode\":{\"name\":\"" + name + "\"}}";
	}

	@Override
	public Set<String> collectVariableNames() {
		Set<String> result = new HashSet<>();
		result.add(name);
		return result;
	}

	@Override
	public Object evaluate(FieldEvaluator evaluator) throws CPSException {
		return evaluator.evaluate(name);
	}

	@Override
	public void updateVariableName(String original, String fullQualifiedName) {
		if(name.equals(original))
			name = fullQualifiedName;
	}

}
